<?php

class Ialbum_Api_Album extends Core_Api_Abstract
{
  public function getAlbumSelect($options = array())
  {
  	$albumTable = Engine_Api::_()->getDbTable('albums', 'album');
    $select = $albumTable->select();
    if( !empty($options['owner']) && 
        $options['owner'] instanceof Core_Model_Item_Abstract ) {
      $select
        ->where('owner_type = ?', $options['owner']->getType())
        ->where('owner_id = ?', $options['owner']->getIdentity());        
    }
	
    if( !empty($options['search']) && is_numeric($options['search']) ) {
      $select->where('search = ?', $options['search']);
    }

    if(!empty($options['album_ignore']) && is_numeric($options['album_ignore'])){
    	$select->where('album_id <> ?', $options['album_ignore']);
    }
    if(!empty($options['order']) && ($options['order'] != '')){
    	$select->order($options['order']);
    }else{
    	$select->order('modified_date DESC');
    }
    return $select;
  }

  public function getAlbumPaginator($options = array())
  {
    return Zend_Paginator::factory($this->getAlbumSelect($options));
  }
}
